<?php
require_once 'ini.php';
use admin\helper\qiniu ;
$error = array();

if ($_GET['act'] && $_GET['act'] == 'edit') {
    //创建或者修改
    $product       = new \admin\helper\product($register);
    $product_id    = $_GET['product_id'];
    $data          = $product->getOneProduct($product_id);
    $data['admin'] = $_SESSION['admin'];

    if ($product_id) {
        //判断权限
        if(!$data['admin']['is_admin'] && $data['admin']['username']!='googleID')
        {
            if($data['aid'] != $data['admin']['uid'] )
            {
                $error['content'] = '你没有权限查看此产品！';
                $error['url']     = "product.php?";
                $register->get('view')->display('error.twig', $error);
                exit;
            }
        }
        //查找属性
        $attr         = $product->getProduct_attr($product_id);
        $data['attr'] = $attr;

        //图集
        $photos         = $db->select('product_thumb', '*', ["ORDER" => ['add_time' => "DESC"], 'product_id' => $product_id]);
        $data['photos'] = $photos;

        //套餐
        $combo         = new \admin\helper\combo($register);
        $combo         = $combo->findCombo($product_id);
        $data['combo'] = $combo;
    } else {
        $data['ad_member_id'] = -1;
    }

    $D                 = new \admin\helper\country($register);
    $id_zone           = $D->getAllZone();
    $data['id_zones']  = $id_zone;
    $_SESSION['token'] = $data['token']     = md5(uniqid(rand(), true));
    $region            = $db->select('region', '*', ['parent_id' => 0]);
    $data['region']    = $region;

    //获取产品分类目录
    $category = new \admin\helper\category($register);

    //查询改产品的分类
    $ret_category = $category->getProductCategory($data['product_id']);
    $modules = $category->getCategoryParent($data['domain']);

    if($modules)
    {
        foreach ($modules as $r) {
            $r['selected'] = $r['id'] == $ret_category['id'] ? 'selected' : '';
            $r['spa']      = '&emsp;&emsp;';
            $array[]       = $r;
        }
        $str = "<option value='\$id' \$selected>\$spacer \$title \$spa\$spa 中文名:\$title_zh</option>";
        $T   = new \lib\tree();
        $T->init($array);

        $module = $T->getTree(0, $str);
    }

    $data['module'] = $module;
    $data['category_title'] = $ret_category['title'];
    $register->get('view')->display('/product/product.twig', $data);
}
else if ($_GET['act'] && $_GET['act'] == 'save') {
    $product    = new \admin\helper\product($register);
    $product_id = $_POST['product_id'];
    $is_edit    = empty($product_id) ? false : true;
    $error = [];

    if (!$_POST['theme']) {
        echo json_encode(['ret'=>0,'msg'=>'请选择主题']);
        exit;
    }

    if (!$_POST['domain']) {
        echo json_encode(['ret'=>0,'msg'=>'域名不能空']);
        exit;
    }
    //允许重复域名
    elseif (isset($_POST['identity_tag']) && !empty($_POST['identity_tag'])) {
        $ret = $product->domainCheck($_POST['domain'], $_POST['identity_tag'], $product_id);
        if (!$ret['ret']) {
            echo json_encode(['ret'=>0,'msg'=>$ret['msg']]);
            exit;
        }
    }

    if (!$_POST['title']) {
        echo json_encode(['ret'=>0,'msg'=>'产品名称不能空']);
        exit;
    }
    //缩略图
    if (!empty($_POST['thumbsUrl'])) {
        $save['thumb'] = qiniu::changImgDomain($_POST['thumbsUrl']);
    }
    //logo
    if (!empty($_POST['logoUrl'])) {
        $save['logo'] =  qiniu::changImgDomain($_POST['logoUrl']);
    }

    //combo
    if($_POST['combo'])
    {
        foreach ($_POST['combo'] as $key => $value) {
            foreach ($value['num'] as $k => $item) {
                if (!$value['erp_id'][$k]) {
                    echo json_encode(['ret'=>1,'msg'=>'套餐产品erpid不能为空']);
                    exit;
                }
            }
        }
    }
    //获取地区查询对应货币以及lang包
    $id_zone                 = $_POST['id_zone'];
    $D                       = new \admin\helper\country($register);
    $zone                    = $D->getOne($id_zone);
    $save['id_zone']         = $id_zone;
    $C                       = new \admin\helper\currency($register);
    $currency                = $C->getOne($zone['currency_id']);
    $save['currency']        = $currency['currency_code'];
    $save['currency_prefix'] = 0;
    $save['currency_code']   = $currency['symbol_right'];
    if ($currency['symbol_left']) {
        $save['currency_prefix'] = 1;
        $save['currency_code']   = $currency['symbol_left'];
    }
    //获取地区 end
    $users = $_POST['users'];
    if(strpos($users,'_')!==false)
    {
        list($ad_member_id,$ad_member) = explode('_',$users);
    }
    else{
        $ad_member_id =$users;
        $ad_member = '';
    }
    if ($ad_member_id ==1 || !$ad_member_id) {
        echo json_encode(['ret'=>0,'msg'=>'请选择优化师或优化师不能为系统']);
        exit;
    }
    if($_POST['identity_tag'])
    {
        $identity_tag = trim($_POST['identity_tag']);
        if(strpos($identity_tag,'/'))
        {
            echo json_encode(['ret'=>0,'msg'=>'二级目录格式不正确，不能使用 斜杠/ ']);
            exit;
        }
        $save['identity_tag']  = $identity_tag;
    }
    $save['lang']          = $_POST['lang'];
    $save['domain']        = trim($_POST['domain']);
    $save['id_department'] = $_POST['id_department'];
    $save['ad_member_id']  = $ad_member_id;
    $save['ad_member'] =  $ad_member; //jimmy fix save ad_member
    $save['tags']          = isset($_POST['tags']) ? trim($_POST['tags']):'';
    $save['theme']         = $_POST['theme'];
    $save['content']       = qiniu::changImgDomain($_POST['content']);
    $save['photo_txt']         = $_POST['photo_txt'];

    $save['price'] = money_int($_POST['price']);
    if (!$_POST['market_price']) {
        $market_price         = round($_POST['price'] / ($_POST['discount'] / 10));
        $save['market_price'] = money_int($market_price);
    }
    else {
        $save['market_price'] = money_int($_POST['market_price']);
    }
    $save['discount']          = money_int($_POST['discount']);
    $save['title']             = $_POST['title'];
    $save['sales_title']       = $_POST['sales_title']; //
    $save['payment_online']    = $_POST['payment_online'];
    $save['payment_underline'] = $_POST['payment_underline'];
    $save['payment_paypal']    = $_POST['payment_paypal'];
    $save['payment_asiabill']  = I('post.payment_asiabill', 0);
    $save['payment_ocean']  = I('post.payment_ocean', 0);
    $save['erp_number']        = trim($_POST['erp_number']);
    $save['la']                = $_POST['la'];
    $fb_px =                    trim($_POST['fb_px']);
    $fb_px = str_replace('，',',',$fb_px);
    $save['fb_px']             = $fb_px;

    $save['sales']               = $_POST['sales'] ?: 1000;
    $save['stock']               = $_POST['stock'] ?: 100;
    $save['service_contact_id']  = $_POST['service_contact_id'];
    $save['service_email']       = $_POST['service_email'];
    $save['google_js']           = $_POST['google_js'];
    $save['google_analytics_js'] = $_POST['google_analytics_js'];
    $save['yahoo_js']            = $_POST['yahoo_js'];
    $save['yahoo_js_trigger']    = $_POST['yahoo_js_trigger'];
    $save['tips']                = $_POST['tips'];
    if (!$_POST['seo_title'] || !$_POST['seo_description']) {
        $save['seo_title']       = $save['seo_description'] = $_POST['title'];
    }
    else {
        $save['seo_title']       = $_POST['seo_title'];
        $save['seo_description'] = $_POST['seo_description'];
    }
    if (!$product_id) {
        $save['add_time'] = date("Y-m-d H:i:s", time());
    }

    $ret = $product->saveProduct($product_id, $save);
    if($ret === false)
    {
        echo json_encode(['ret'=>0,'msg'=>'保存产品失败']);
        exit;
    }

    //保存产品分类
    $cat_product_id = empty($product_id) ? $ret:$product_id;
    if ($cat_product_id) {
        $category_id = $_POST['product_category'];
        if ($category_id != 0) {
            $category = new \admin\helper\category($register);
            $ret_cat = $category->saveProductCategory(['category_id'=>$category_id, 'product_id'=>$cat_product_id]);
        }
    }

    //插入属性
    if (!$product_id) {
        $product_id = $ret;
    }
    //判断是否有编辑的属性，有就写入
    if($_POST['product_attr_id'])
    {
        foreach ($_POST['product_attr_id'] as $k => $v) {
            $upAttr =[];
            $upAttr['name']             = trim($_POST['up_name'][$k]);
            $upAttr['attr_group_id']    = $_POST['up_attr_group_id'][$k];
            $upAttr['attr_group_title'] = trim($_POST['up_attr_group_title'][$k]);
            $upAttr['number']           = $_POST['up_number'][$k];
            if($_POST['attr_thumb_url'][$k])
            {
                $upAttr['thumb'] = qiniu::changImgDomain($_POST['attr_thumb_url'][$k]);
            }
            $product->saveProductAttr($v, $upAttr);
        }
    }
    if ($_POST['attr_group_id']) {
        foreach ($_POST['attr_group_id'] as $key => $t) {
            $attrArray[$key]['name']             = $_POST['name'][$key];
            $attrArray[$key]['attr_group_id']    = $t;
            $attrArray[$key]['product_id']       = $product_id;
            $attrArray[$key]['thumb']            = qiniu::changImgDomain($_POST['attr_thumb'][$key]);
            $attrArray[$key]['attr_group_title'] = trim($_POST['attr_group_title'][$key]);
            $attrArray[$key]['number']           = trim($_POST['attr_erp_number'][$key]);
        }
        if($attrArray)
        {
            $ret = $product->addProductAttr($attrArray);
        }
    }
    //判断是否上传图集
    if (count($_POST['photos'])) {
        $photos = [];
        foreach ($_POST['photos'] as $key => $value) {
            $photos[$key]['thumb']      =  qiniu::changImgDomain($value);
            $photos[$key]['add_time']   = date('Y-m-d H:i:s', time());
            $photos[$key]['product_id'] = $product_id;
        }
        //插入图集
        if (count($photos) > 0) {
            $db->insert('product_thumb', $photos);
        }
    }

    //是否有套餐
    if ($_POST['combo']) {
        //检测套餐产品是否存在重复
//        foreach ($_POST['combo'] as $key => $checkCombo)
//        {
//            $check =[];
//            foreach ($checkCombo['num'] as $k=>$checkNum)
//            {
//                $product_id = $checkCombo['product_id'][$k];
//                if(isset($check[$product_id]))
//                {
//                    echo json_encode(['ret'=>0,'msg'=>'保存套餐失败,同一个套餐不能存在相同产品']);
//                    exit;
//                }
//                $check[$product_id]  = $product_id;
//            }
//        }
        ////插入更新
        foreach ($_POST['combo'] as $key => $value) {
            //判断是更新还是新增
            $combo_id = $value['combo_id'];
            $combo['title']      = $value['name'];
            $combo['price']      = money_int($value['price']);
            $combo['product_id'] = $product_id;
            if($value['thumb'])
            {
                $combo['thumb']      = qiniu::changImgDomain($value['thumb']);
            }
            if($combo_id)
            {
                $db->update('combo', $combo,['combo_id'=>$combo_id]);
            }
            else{
                //插入套餐
                $combo_id            = $db->insert('combo', $combo);
            }
            $comboGoods =[];
            foreach ($value['num'] as $k => $item) {
                $combo_goods_id = $value['combo_goods_id'][$k];
                if($combo_goods_id){
                    $comboGoodsEdit['num']        = $item;
                    $comboGoodsEdit['erp_id']     = $value['erp_id'][$k];
                    $comboGoodsEdit['product_id'] = $value['product_id'][$k];
                    $comboGoodsEdit['combo_id']   = $combo_id;
                    $comboGoodsEdit['title']      = $value['title'][$k];
                    $comboGoodsEdit['sale_title'] = $value['sale_title'][$k] ;
                    $db->update('combo_goods', $comboGoodsEdit,['combo_goods_id'=>$combo_goods_id]);
                    continue;
                }
                $comboGoods[$k]['num']        = $item;
                $comboGoods[$k]['erp_id']     = $value['erp_id'][$k];
                $comboGoods[$k]['product_id'] = $value['product_id'][$k];
                $comboGoods[$k]['combo_id']   = $combo_id;
                $comboGoods[$k]['title']      = $value['title'][$k];
                $comboGoods[$k]['sale_title'] = empty($value['sale_title'][$k]) ?  $value['title'][$k] :$value['sale_title'][$k] ;
            }
            if($comboGoods)
            {
                $db->insert('combo_goods', $comboGoods);
            }
        }
    }
    $url = '/product.php?act=edit&product_id='.$product_id;
    echo json_encode(['ret'=>1,'msg'=>'保存成功','url'=>$url]);
}
elseif($_GET['act'] && $_GET['act'] == 'googleSave'){
    $data = $_POST;
    $product_id = $data['product_id'];
    $map=['product_id'=>$product_id];
    unset($data['product_id'],$data['google_analytics_id']);
    $db->update('product',$data,$map);
    $url = '/product.php?act=edit&product_id='.$product_id;
    echo json_encode(['ret'=>1,'msg'=>'保存成功','url'=>$url]);
}
elseif ($_GET['act'] && $_GET['act'] == 'add') {
    $data['admin'] = $_SESSION['admin'];
    $register->get('view')->display('/product/product.twig', $data);
}
elseif ($_POST['act'] && $_POST['act'] == 'delete') {

    $product_attr_id = $_POST['product_attr_id'];
    $product         = new \admin\helper\product($register);
    $ret             = $product->deleteAttr($product_attr_id);
    echo json_encode($ret);
}
elseif ($_POST['act'] && $_POST['act'] == 'del') {
    $product_id     = $_POST['product_id'];
    $product        = new \admin\helper\product($register);
    $data['is_del'] = $_POST['is_del'];
    $ret            = $product->delProduct($product_id, $data);
    echo json_encode($ret);
}
elseif ($_POST['act'] && $_POST['act'] == 'departmentChange') {
    $domain        = $_POST['domain'];
    $id_department = $_POST['id_department'];
    $product       = new \admin\helper\product($register);
    $ret           = $product->departmentChange($domain, $id_department);
    echo json_encode($ret);
}
elseif (isset($_POST['act']) && $_POST['act'] == 'productDepartChange') {
    $productIDs    = isset($_POST['products'])?$_POST['products']:null;
    $id_department = isset($_POST['id_department'])?$_POST['id_department']:null;
    $product       = new \admin\helper\product($register);
    $ret           = $product->updateProductDepartment($productIDs, $id_department);
    echo json_encode($ret);
}
elseif ($_POST['act'] && $_POST['act'] == 'deleteCombo') {
    $combo_id = $_POST['combo_id'];
    $product  = new \admin\helper\combo($register);
    $ret      = $product->delCombo($combo_id);
    echo json_encode($ret);
}
//删除套餐产品
elseif ($_POST['act'] && $_POST['act'] == 'deleteComboGoods') {
    $id = $_POST['combo_goods_id'];
    $product  = new \admin\helper\combo($register);
    $ret      = $product->delComboGoods($id);
    echo json_encode($ret);
}
elseif ($_GET['act'] && $_GET['act'] == 'downloadexcel') {
    $map['ORDER'] = ['product_id' => "DESC"];
    $map['is_del'] =0;
    if(!$_SESSION['admin']['is_admin'])
    {
        $map['aid']  =  $_SESSION['admin']['uid'];
    }
    $data = $db->select('product', '*', $map);
    Header("Content-type:   application/octet-stream ");
    Header("Accept-Ranges:   bytes ");
    Header("Content-type:application/vnd.ms-excel ");
    Header("Content-Disposition:attachment;filename=产品域名.xls ");

    echo "<table  border='1'>";
    //var_dump($data);die;
    //domain,identity_tag,title,erp_number,fb_px,
    echo "<tr align='center'>";
    echo " <td width='200'>产品名称</td>";
    echo " <td width='200'>erp域名</td>";
    echo " <td width='200'>建站域名</td>";
    echo " <td width='200'>二级目录</td>";
    echo " <td width='200'>ERP产品id</td>";
    echo " <td width='200'>FB通用像素id</td>";
    echo " <td width='200'>广告手id</td>";
    echo " <td width='200'>价格</td>";
    echo " <td width='200'>前台显示模板</td>";
    echo "</tr>";
    foreach ($data as $k => $v) {
        echo "<tr align='center'>";
        echo "<td width='200'>" . $v['title'] . "</td>";
        echo "<td width='200'>" . $v['domain'] . "</td>";
        echo "<td width='200'>http://" . $v['domain'] . "/" . $v['identity_tag'] . "</td>";
        echo "<td width='200'>" . $v['identity_tag'] . "</td>";
        echo "<td width='200'>" . $v['erp_number'] . "</td>";
        echo "<td width='200'>" . $v['fb_px'] . "</td>";
        echo "<td width='200'>" . $v['ad_member_id'] . "</td>";
        echo "<td width='200'>" . $v['price'] / 100 . "</td>";
        echo "<td width='200'>" . $v['theme'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";

    //var_dump($data);
    //echo 111;
    exit;
}
//mike：导出产品id和域名
elseif ($_GET['act'] && $_GET['act'] == 'downloadid') {
    $data = $db->select('product', '*', ["ORDER" => ['product_id' => "DESC"], 'AND' => ['is_del' => 0]]);
    Header("Content-type:   application/octet-stream ");
    Header("Accept-Ranges:   bytes ");
    Header("Content-type:application/vnd.ms-excel ");
    Header("Content-Disposition:attachment;filename=产品ID和域名.xls ");

    echo "<table  border='1'>";
    //var_dump($data);die;
    //domain,identity_tag,title,erp_number,fb_px,
    echo "<tr align='center'>";
    echo " <td width='200'>产品ID</td>";
    echo " <td width='200'>建站域名</td>";
    echo "</tr>";
    foreach ($data as $k => $v) {
        echo "<tr align='center'>";
        echo "<td width='200'>" . $v['product_id'] . "</td>";
        echo "<td width='200'>http://" . $v['domain'] . "/" . $v['identity_tag'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";

    //var_dump($data);
    //echo 111;
    exit;
}
elseif ($_POST['act'] && $_POST['act'] == 'check') {
    $domain = $_POST['domain'];
    //获取域名信息
    $product = new \admin\helper\product($register);
    $ret = $product->getErpDomainInfo($domain);

    if (!$ret['status']) {
        echo json_encode(['ret' => 0, 'msg' => "没找到该域名信息，请确认。"]);
        exit;
    }

    //获取产品分类目录
    $category = new \admin\helper\category($register);
    //查询改产品的分类
    $modules = $category->getCategoryParent($domain);
    if($modules)
    {
        foreach ($modules as $r) {
            $r['spa']  = '&emsp;&emsp;';
            $array[]   = $r;
        }
        $str = "<option value='\$id'>\$spacer \$title \$spa 中文名:\$title_zh</option>";
        $T   = new \lib\tree();
        $T->init($array);
        $module = $T->getTree(0, $str);
    }

    echo json_encode(['ret' => 1, 'data' => $ret['data'], 'module' => $module]);
}
elseif ($_POST['act'] && $_POST['act'] == 'getErpProduct') {

    $product_id = $_POST['product_id'];
    $erp_number = $_POST['number'];
    $product    = new \admin\helper\product($register);
    $uri        = 'http://ddnerp.stosz.com/Product/Api/get?id=' . $erp_number;
    $ret        = file_get_contents($uri);
    $ret        = json_decode($ret, true);

    if (!$ret['status']) {
        echo json_encode(['ret' => 0, 'msg' => "没找到该差产品信息，请确认。"]);
        exit;
    }

    echo json_encode(['ret' => 1, 'data' => $ret['product']]);
}
elseif ($_POST['act'] && $_POST['act'] == 'deletePhotos') {
    $thumb_id = $_POST['thumb_id'];
    $map      = ['thumb_id' => $thumb_id];
    $ret      = $db->delete('product_thumb', $map);

    if ($ret) {
        echo json_encode(['ret' => 1, 'msg' => "OK"]);
        exit;
    }

    echo json_encode(['ret' => 0, 'error' => "删除失败。"]);
}
elseif($_POST['act'] && $_POST['act'] == 'delAttrThumb'){
    $id = $_POST['product_attr_id'];

    if($id){
        $ret      = $db->update('product_attr', ['thumb'=>''],['product_attr_id'=>$id]);
    }
    echo json_encode(['ret' => 1, 'error' => "删除成功"]);
}
elseif ($_GET['act'] && $_GET['act'] == 'publicProduct') {
    if ($_POST) {
        $value = trim($_POST['keyword']);
        if ($_POST['type'] == 'title') {
            $filter['title[~]'] = ['like', '%' . $value . '%'];
        }
        else if ($_POST['type'] == 'erpid'){
            $filter['erp_number'] = $value;
        }else if ($_POST['type'] == 'domain'){
            $filter['domain'] = $value;
        }
    }
    if(isset($_GET['id_zone'])){
        $filter['id_zone'] = $_GET['id_zone'];
    }
    $product           = new \admin\helper\product($register);
    $filter['is_del']  = 0;
    $data              = $product->getAllProduct($filter, 10);
    $filter['keyword'] = $value;
    $data['filter']    = $filter;
    if($filter['id_zone'])
    {
        $data['id_zone'] =  $filter['id_zone'];
    }

    if (isset($_GET['self']) && $_GET['self'] == 1) {
        $register->get('view')->display('/product/public_product_self.twig', $data);
    }
    else {
        $register->get('view')->display('/product/public_product.twig', $data);
    }
}
elseif ($_GET['act'] && $_GET['act'] == 'publicProduct2') {
    if ($_POST) {
        $value = trim($_POST['keyword']);
        if ($_POST['type'] == 'title') {
            $filter['title[~]'] = ['like', '%' . $value . '%'];
        }
        else {
            $filter['erp_number'] = $value;
        }
    }
    $product           = new \admin\helper\product($register);
    $filter['is_del']  = 0;
    $data              = $product->getAllProduct($filter, 10);
    $filter['keyword'] = $value;
    $data['filter']    = $filter;
    echo json_encode($data);
    // if (isset($_GET['self']) && $_GET['self'] == 1) {
    //     $register->get('view')->display('/product/public_product_self.twig', $data);
    // }
    // else {
    //     $register->get('view')->display('/product/public_product.twig', $data);
    // }
}
else if (isset($_POST['act']) && $_POST['act'] == 'seo') {

    //获取域名判断是否为空
    $domain = $_POST['domain'];
    if (!$domain) {
        echo json_encode(array('ret'=>0, 'msg'=>'请求域名为空'));
        exit;
    }

    //erp信息
    $uri         = 'http://ddnerp.stosz.com/Domain/Api/get_all?name=' . $_POST['domain'];
    $info        = file_get_contents($uri);
    $info        = json_decode($info, true);

    $users = $info['data']['users'];
    if ($users) {
        echo json_encode(array('ret'=>1, 'msg'=>'查询成功', 'data'=>$info['data']['users']));
    } else {
        echo json_encode(array('ret'=>0, 'msg'=>'查询优化师加载失败'));
    }
}
elseif(isset($_POST['act']) && $_POST['act'] == 'copy')
{
    //复制一条产品
    $product        = new \admin\helper\product($register);
    $data['id'] = $_POST['product_id'];
    $data['id_zone'] = $_POST['id_zone'];
    $data['identity_tag'] = $_POST['identity_tag'];
    $data['domain'] = $_POST['domain'];
    $ret = $product->productCopy($data);
    echo json_encode($ret);
}
else {
    $filter = [];
    $info   = [];
    if ($_GET['title']) {
        $filter['title[~]'] = ["%" . $_GET['title'] . '%'];
        $info['title']      = $_GET['title'];
    }
    if ($_GET['domain']) {
        $domain  = $_GET['domain'];
        if(strpos($domain,'/')!==false)
        {
            list($mapDomain,$tag) = explode('/',$domain);
            $filter['identity_tag'] = $tag;
        }
        else{
            $mapDomain = $domain;
        }
        $filter['domain[~]'] = ["%" . $mapDomain . '%'];
        $info['domain']      = $domain;
    }
    if ($_GET['theme']) {
        $filter['theme[~]'] = ["%" . $_GET['theme'] . '%'];
        $info['theme']      = $_GET['theme'];
    }
    if ($_GET['erp_id']) {
        $filter['erp_number'] = $_GET['erp_id'];
        $info['erp_id']       = $_GET['erp_id'];
    }

    if ($_GET['product_id']){
        $filter['product_id'] = $_GET['product_id'];
        $info['product_id']       = $_GET['product_id'];
    }

    if (isset($_GET['is_del'])) {
        if ($_GET['is_del'] != -1) {
            $filter['is_del'] = $_GET['is_del'];
        }

        $info['is_del'] = $_GET['is_del'];
    }
    else {
        $info['is_del']   = $filter['is_del'] = 0;
    }

    if (isset($_GET['aid'])) {
        if ($_GET['aid'] != -1) {
            $filter['aid'] = $_GET['aid'];
        }
        $info['aid'] = $_GET['aid'];
    }

    $product        = new \admin\helper\product($register);
    $data           = $product->getAllProduct($filter);
    $data['admin']  = $_SESSION['admin'];
    $data['filter'] = $info;
    //user
    $user = $register->get('db')->select('user',['uid','username']);
    $data['user'] = $user;
    if( isset($_GET['json']) && $_GET['json']=='1' ){
        echo json_encode($data);
    }else{
        $register->get('view')->display('/product/product_list.twig', $data);
    }

}
